class Solution
{
public:
    int maxPalindromesAfterOperations(vector<string> &words)
    {
        vector<int> charCount(26, 0);
        for (auto &word : words)
        {
            for (auto &c : word)
            {
                charCount[c - 'a']++;
            }
        }

        vector<int> wordLens;
        for (auto &word : words)
        {
            wordLens.push_back(word.size());
        }
        sort(wordLens.begin(), wordLens.end());

        int result = 0;
        for (int len : wordLens)
        {
            while (len > 0)
            {
                if (len & 1)
                {
                    bool found = false;
                    for (int i = 0; i < 26; i++)
                    {
                        if (charCount[i] & 1)
                        {
                            charCount[i]--;
                            len--;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        for (int i = 0; i < 26; i++)
                        {
                            if (charCount[i] > 0)
                            {
                                charCount[i]--;
                                len--;
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found)
                    {
                        break;
                    }
                }

                else
                {
                    bool found = false;
                    for (int i = 0; i < 26; i++)
                    {
                        int count = charCount[i] / 2 * 2;
                        if (count == 0)
                        {
                            continue;
                        }
                        count = min(count, len);
                        charCount[i] -= count;
                        len -= count;
                        found = true;
                    }
                    if (!found)
                    {
                        break;
                    }
                }
            }
            if (len == 0)
            {
                result++;
            }
            else
            {
                break;
            }
        }
        return result;
    }
};